package com.learn.springboot.controller.database;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * jdbc配置多数据源
 * @author wangxing
 * @version 2020/8/3 14:31 Administrator
 */
//@RestController
//@RequestMapping("/jdbc")
public class JdbcController {
    Logger logger = LoggerFactory.getLogger(JdbcController.class);
    /**
     * 数据源1
     */
    @Autowired
    @Qualifier("primaryJdbcTemplate")
    private JdbcTemplate primaryJdbcTemplate;
    /**
     * 数据源2
     */
    @Autowired
    @Qualifier("secondaryJdbcTemplate")
    private JdbcTemplate secondaryJdbcTemplate;

    @GetMapping("/umsAdmin/count")
    public String queueUmsAdminAllCount(){
        String sql = " select count(1) count from ums_admin ";
        Integer countOne = primaryJdbcTemplate.queryForObject(sql, Integer.class);
        logger.info("countOne umsAdmin num is {}",countOne);
        Integer countTwo = secondaryJdbcTemplate.queryForObject(sql, Integer.class);
        logger.info("countTwo umsAdmin num is {}",countTwo);
        return "success";
    }



}
